﻿@using OSBLE.Models.HomePage

<ul id="notifications_list">
  
    @foreach (Notification n in ViewBag.Notifications)
    {
       
        if (n == null || n.Sender == null)
        {
            continue;
        }
        string classToAppend = "";
        if (n.Read)
        {
            classToAppend = "read";
        }
        <li class="notification @classToAppend" id="notification_@(n.ID)" >
            <time class="course-local-time">
                @n.Posted.UTCToCourse(n.Recipient.AbstractCourseID).ToShortDateString() @n.Posted.UTCToCourse(n.Recipient.AbstractCourseID).ToShortTimeString()</time>&nbsp;
            
            @if (ViewBag.ShowNotificationDelete == true)
            {
                <div class="notification_tools">
                    <form action="@Url.Action("MarkAsRead", "Notification", new { ID = @n.ID })"
                                style="display: inline;"
                                data-ajax="true"
                                data-ajax-success="$('#notification_@(n.ID)').hide('highlight',{},'slow',function(){
                                        $(this).remove();
                                    });"
                                method="post">
                    @Helpers.DeleteSubmit("Mark This Notification As Read")
                    </form>
                </div>
            }
            <div class="notification_text">
                @switch (n.ItemType)
                {
                    case Notification.Types.Mail:
                        {
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> sent you a @NotificationLink(n.ID, "message")</text>
                            break;
                        }
                    case Notification.Types.EventApproval:
                        {                                     
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> submitted an @NotificationLink(n.ID, "event for approval")</text>
                            break;
                        }
                    case Notification.Types.JoinCourseApproval:
                        {
                            <text><em>@n.Sender.DisplayNameFirstLast(ViewBag.ActiveCourse.AbstractRole)</em> sent you a @NotificationLink(n.ID, "request to join course")</text>
                            break;

                        }
                     case Notification.Types.JoinCommunityApproval:
                        {
                            <text><em>@n.Sender.DisplayNameFirstLast(ViewBag.ActiveCourse.AbstractRole)</em> sent you a @NotificationLink(n.ID, "request to join community")</text>
                            break;
                        }
                    case Notification.Types.Dashboard:
                        {
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> posted in a @NotificationLink(n.ID, "dashboard thread")
                            that you participated in</text>
                            break;
                        }
                    case Notification.Types.InlineReviewCompleted:
                        {
                            string[] args = n.Data.Split(new char[] { ';' });
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> has published an
                            @Html.ActionLink("inline review", "ViewInlineReview", "Assignment", new { assignmentID = args[0], teamID = args[1] }, new { }) of your @args[2]</text>
                            break;
                        }
                    case Notification.Types.RubricEvaluationCompleted:
                        {
                            string[] args1 = n.Data.Split(new char[] { ';' });
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> completed an @Html.ActionLink("evaluation rubric", "View", "Rubric", new { assignmentId = args1[0], cuId = args1[1] }, new { }) of your @args1[2]
                            </text>
                            break;
                        }
                    case Notification.Types.FileSubmitted:
                        {
                            string[] args2 = n.Data.Split(new char[] { ';' });
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> submitted the file @args2[4] for the assignment '@args2[2]' at @args2[5] download it
                            @Html.ActionLink("here", "GetSubmissionZip", "FileHandler", new { assignmentID = args2[0], teamID = args2[1] }, new { })</text>
                            break;
                        }
                    case Notification.Types.TeamEvaluationDiscrepancy:
                        {
                            string[] args = n.Data.Split(new char[] { ';' });
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> submitted a 
                            @Html.ActionLink("team evaluation", "TeacherTeamEvaluation", "Assignment", new { precedingTeamId = args[0], TeamEvaluationAssignmentId = args[1] }, new { })
                            with a large percent spread</text>
                            break;
                        }
                    case Notification.Types.UserTag:
                        {
                            <text><em>@n.Sender.DisplayName(ViewBag.ActiveCourse.AbstractRole)</em> tagged you in a
                            @Html.ActionLink("post", "Dispatch", "Notification", new { id = n.ID }, new { })
                            </text>
                            break;
                        }

                }
            </div>
        </li>
    }
</ul>
@helper NotificationLink(int id, string name)
    {
    @Html.ActionLink(name, "Dispatch", "Notification", new { ID = id }, new { });
}
